﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Collections.TreeCollections;
using FeatureModelCore.FMTypes;
using Collections;
using FeatureModelCore.FMInterface;
using FeatureModelCore.FMCrossTreeConstraint;

namespace FeatureModelCore.Optimized
{
    public class OptimizedGroupRelationship : TreeNode, IOptimizableRelation
    {
        #region Properties
        public FMTreeGroupRelationshipType Type { get; protected set; }
        public IFeatureModelObject StandardFeatureObject { get { return _standardRelation; } }
        public FeatureTreeObjectExtension ObjectExtension { get { return _extension; } }
        public IFeature[] ChildrenNodes { get { return getChildrenFeature(); } }
        public IFeature ParentNode { get { return (IFeature)Parent; } }
        #endregion

        #region Fields
        private FeatureTreeGroupRelationship _standardRelation;
        private FeatureTreeObjectExtension _extension;

        #endregion
        public OptimizedGroupRelationship(FeatureTreeGroupRelationship relation)
            : base(relation.ID)
        {
            _standardRelation = relation;
            _extension = new FeatureTreeObjectExtension(this);
            Type = relation.Type;
        }

        #region Get Objects

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private IFeature[] getChildrenFeature()
        {
            List<IFeature> features = new List<IFeature>();
            foreach (INonRoot nonRoot in this.Children)
            {
                if (nonRoot is IFeature)
                {
                    features.Add((IFeature)nonRoot);
                }
            }
            return features.ToArray<IFeature>();
        }
        #endregion


        public override string ToString()
        {
            return _standardRelation.Type.ToString();
        }

        public override TreeRoot Parse2TreeRoot()
        {
            throw new NotImplementedException();
        }

        public override object Clone()
        {
            throw new NotImplementedException();
        }
    }
}
